﻿using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;
using Sharp.Domain.PlatformBoundedContext.PersonModule.Aggregates;

namespace Sharp.Domain.PlatformBoundedContext.ModelConfigurations
{
    public partial class PersonConfiguration
        : EntityTypeConfiguration<Person>
    {
        public PersonConfiguration()
        {
            // keys
            HasKey(t => t.Id);

            // Properties
            Property(t => t.Id)
                .IsRequired()
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);
              
            Property(t => t.RegisteredResidence)
                .HasMaxLength(50)
                .IsOptional();
            //Property(t => t.WorkDate)
            //    .HasMaxLength(8)
            //    .IsOptional();

             
            // Relationships


            HasOptional(t => t.Org).WithMany(t => t.People).HasForeignKey(d => d.OrgId);

            this.HasOptional(t => t.User).WithOptionalDependent(x => x.Person).WillCascadeOnDelete(false);


        }
    }
}

